#ifndef WEBSERVER_H
#define WEBSERVER_H

#include <string>
#include <map>

///////////////////////////////////////////////////////////////////////////////
//
// enum Definitions
//
///////////////////////////////////////////////////////////////////////////////

enum EXTENSION
{
	HTML=1,
	GIF,
	JPEG,
	PNG,
	TIFF,
	TXT
};

enum HTTP_HEADER_METHOD
{
	GET=1,
	POST,
	HEAD,
	DELETE
};

enum HTTP_HEADER_FIELD
{
	ACCEPT=1,
	ACCEPT_CHARSET,
	ACCEPT_ENCODING,
	ACCEPT_LANGUAGE,
	AUTHORIZATION,
	COOKIE,
	EXPECT,
	FROM,
	HOST,
	IF_MATCH,
	IF_MODIFIED_SINCE,
	IF_NONE_MATCH,
	IF_RANGE,
	IF_UNMODIFIED_SINCE,
	MAX_FORWARDS,
	PROXY_AUTHORIZATION,
	RANGE,
	REFERER,
	TE,
	UPGRADE,
	USER_AGENT,
	
	// RESPONSE ONLY
	ACCEPT_RANGES,
	AGE,
	ALLOW,
	CONTENT_ENCODING,
	CONTENT_LANGUAGE,
	CONTENT_LOCATION,
	CONTENT_DISPOSITION,
	CONTENT_RANGE,
	ETAG,
	EXPIRES,
	LAST_MODIFIED,
	LINK,
	LOCATION,
	P3P,
	PROXY_AUTHENTICATE,
	REFRESH,
	RETRY_AFTER,
	SERVER,
	SET_COOKIE,
	STRICT_TRANSPORT_SECURITY,
	TRAILER,
	TRANSFER_ENCODING,
	VARY,
	WWW_AUTHENTICATE,
	
	// REQUEST & RESPONSE
	CACHE_CONTROL,
	CONNECTION,
	CONTENT_LENGTH,
	CONTENT_MD5,
	CONTENT_TYPE,
	DATE,
	PRAGMA,
	VIA,
	WARNING
};

///////////////////////////////////////////////////////////////////////////////
//
// Typedefs
//
///////////////////////////////////////////////////////////////////////////////

typedef std::map<HTTP_HEADER_FIELD, std::string> tdFieldDataMap;
typedef std::map<std::string, HTTP_HEADER_FIELD> tdFieldMap;
typedef std::map<std::string, HTTP_HEADER_METHOD> tdMethodMap;
typedef std::map<int, std::string> tdStatusMap;
typedef std::map<std::string, EXTENSION> tdExtensionMap;

///////////////////////////////////////////////////////////////////////////////
//
// Global map initialization functions
//
///////////////////////////////////////////////////////////////////////////////

tdExtensionMap create_extension_map()
{
	tdExtensionMap temp;
	
	temp["html"] = HTML;
	temp["gif"] = GIF;
	temp["jpg"] = JPEG;
	temp["png"] = PNG;
	temp["tiff"] = TIFF;
	temp["txt"] = TXT;
	
	return temp;
}

tdStatusMap create_status_map()
{
	tdStatusMap temp;
	
	temp.insert( std::pair<int, std::string>(200, "HTTP/1.1 200 OK") );
	temp.insert( std::pair<int, std::string>(201, "HTTP/1.1 201 Created") );
	temp.insert( std::pair<int, std::string>(202, "HTTP/1.1 202 Accepted") );
	temp.insert( std::pair<int, std::string>(204, "HTTP/1.1 204 No Content") );
	temp.insert( std::pair<int, std::string>(301, "HTTP/1.1 301 Moved Permanently") );
	temp.insert( std::pair<int, std::string>(302, "HTTP/1.1 302 Moved Temporarily") );
	temp.insert( std::pair<int, std::string>(304, "HTTP/1.1 304 Not Modified") );
	temp.insert( std::pair<int, std::string>(400, "HTTP/1.1 400 Bad Request") );
	temp.insert( std::pair<int, std::string>(401, "HTTP/1.1 401 Unauthorized") );
	temp.insert( std::pair<int, std::string>(403, "HTTP/1.1 403 Forbidden") );
	temp.insert( std::pair<int, std::string>(404, "HTTP/1.1 404 Not Found") );
	temp.insert( std::pair<int, std::string>(500, "HTTP/1.1 500 Internal Server Error") );
	temp.insert( std::pair<int, std::string>(501, "HTTP/1.1 501 Not Implemented") );
	temp.insert( std::pair<int, std::string>(502, "HTTP/1.1 502 Bad Gateway") );
	temp.insert( std::pair<int, std::string>(503, "HTTP/1.1 503 Service Unavailable") );
	
	return temp;
}

tdMethodMap create_method_map()
{
	tdMethodMap temp;
	
	temp["GET"] = GET;
	temp["POST"] = POST;
	temp["HEAD"] = HEAD;
	temp["DELETE"] = DELETE;
	
	return temp;
}

tdFieldMap create_field_map()
{
	tdFieldMap temp;
	
	// Request only
	temp["Accept"] = ACCEPT;
	temp["Accept-Charset"] = ACCEPT_CHARSET;
	temp["Accept-Encoding"] = ACCEPT_ENCODING;
	temp["Accept-Language"] = ACCEPT_LANGUAGE;
	temp["Authorization"] = AUTHORIZATION;
	temp["Cookie"] = COOKIE;
	temp["Expect"] = EXPECT;
	temp["From"] = FROM;
	temp["Host"] = HOST;
	temp["If-Match"] = IF_MATCH;
	temp["If-Modified_Since"] = IF_MODIFIED_SINCE;
	temp["If-None_Match"] = IF_NONE_MATCH;
	temp["If-Range"] = IF_RANGE;
	temp["If-Unmodified-Since"] = IF_UNMODIFIED_SINCE;
	temp["Max-Forwards"] = MAX_FORWARDS;
	temp["Proxy-Authorization"] = PROXY_AUTHORIZATION;
	temp["Range"] = RANGE;
	temp["Referer"] = REFERER;
	temp["TE"] = TE;
	temp["Upgrade"] = UPGRADE;
	temp["User-Agent"] = USER_AGENT;
	
	// Response only
	temp["Accept-Ranges"] = ACCEPT_RANGES;
	temp["Age"] = AGE;
	temp["Allow"] = ALLOW;
	temp["Content-Encoding"] = CONTENT_ENCODING;
	temp["Content-Language"] = CONTENT_LANGUAGE;
	temp["Content-Location"] = CONTENT_LOCATION;
	temp["Content-Disposition"] = CONTENT_DISPOSITION;
	temp["Content-Range"] = CONTENT_RANGE;
	temp["ETag"] = ETAG;
	temp["Expires"] = EXPIRES;
	temp["Last-Modified"] = LAST_MODIFIED;
	temp["Link"] = LINK;
	temp["Location"] = LOCATION;
	temp["P3P"] = P3P;
	temp["Proxy-Authenticate"] = PROXY_AUTHENTICATE;
	temp["Refresh"] = REFRESH;
	temp["Retry-After"] = RETRY_AFTER;
	temp["Server"] = SERVER;
	temp["Set-Cookie"] = SET_COOKIE;
	temp["Strict-Transport-Security"] = STRICT_TRANSPORT_SECURITY;
	temp["Trailer"] = TRAILER;
	temp["Transfer-Encoding"] = TRANSFER_ENCODING;
	temp["Vary"] = VARY;
	temp["WWW-Authenticate"] = WWW_AUTHENTICATE;
	
	// Request & Response
	temp["Cache-Control"] = CACHE_CONTROL;
	temp["Connection"] = CONNECTION;
	temp["Content-Length"] = CONTENT_LENGTH;
	temp["Content-MD5"] = CONTENT_MD5;
	temp["Content-Type"] = CONTENT_TYPE;
	temp["Date"] = DATE;
	temp["Pragma"] = PRAGMA;
	temp["Via"] = VIA;
	temp["Warning"] = WARNING;
	
	return temp;
}

#endif // WEBSERVER_H

